package com.easyjob.config;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author Const
 */
@Component
public class AutoSaveConsumer {
    @Autowired
//    private ExamService examService;

    @RabbitListener(queues = "exam.autoSave")
    public void handleAutoSave(String message) {
        try {
            JSONObject json = JSON.parseObject(message);
            JSONObject payload = json.getJSONObject("payload");

            String examId = payload.getString("examId");
            String questionId = payload.getString("questionId");
            String userId = payload.getString("userId");
            String answer = payload.getString("answer");

//            examService.autoSaveAnswer(examId, questionId, userId, answer);

        } catch (Exception e) {
            // 记录错误日志，可添加重试逻辑
            System.err.println("自动保存失败: " + e.getMessage());
        }
    }
}
